"use strict";
cc._RF.push(module, 'c7094ixUcFBUre889NU4eb+', 'ChooseHoreViewUI');
// scripts/ChooseHoreViewUI.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("ModuleUI"),
    l = e("CommonHelper"),
    _ = e("Game"),
    c = e("RoleSoldierInfo"),
    d = e("ShopViewUI"),
    h = e("sdkConfig"),
    u = e("AD"),
    p = e("Toast"),
    m = e("choose_dower_info"),
    f = e("choose_player_info"),
    v = e("choose_role_item"),
    g = e("GetZsViewUI"),
    y = cc._decorator,
    I = y.ccclass,
    w = y.property,
    b = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.mode_type_sprite = null, t.mode_hero_sprite = null, t.left_pleyer_node = null, t.right_player_node = null, t.time_num_label = null, t.hero_view_ui = null, t.hero_node_item = null, t.hero_view_count = null, t.get_way_node = null, t.get_btn_node = null, t.sure_btn_node = null, t.choose_hero_skill_view = null, t.my_choose_hero_skeleton = null, t.hero_name_sprite = null, t.skill_base_node = null, t.choose_dower_node = null, t.dower_btn_node = null, t.reelect_btn = null, t.GameHeroList = [], t.choose_hero_index = 0, t.choose_skill = [1, 2], t.count_down = 15, t.is_use_card = !1, t;
  }

  return nn(t, e), t.prototype.initView = function () {
    e.prototype.initView.call(this), n.GlobalParams.JoinMatchGame = !0, r["default"].getInstance().playFx("choose_hero"), this.choose_hero_index = 0, this.hero_view_ui.active = !0, this.choose_hero_skill_view.active = !1, this.get_btn_node.parent.active = !1, this.get_way_node.active = !1, this.sure_btn_node.active = !0, this.is_use_card = !1, this.sure_btn_node.getComponent(cc.Button).interactable = !0, this.mode_type_sprite.spriteFrame = i["default"].getInstance().getModeInfoFrame("mode_type_" + n.GlobalParams.ChangeGameMode), n.GlobalParams.ChangeGameMode == _.GameType.clone_mode ? (this.count_down = 20, this.reelect_btn.active = !1) : this.reelect_btn.active = !0, this.showPlayerViewInfo(), this.showGameHeroView(), this.showCountDown(), this.showDowerInfo();
  }, t.prototype.addEvent = function () {
    this.attachEvent(a["default"].SEND_CHOOSE_ROLE_INDEX_INFO, this.chooseRoleInfo, this);
  }, t.prototype.OnClick = function (t) {
    var o = this;
    e.prototype.OnClick.call(this, t);
    var a = t.node,
        i = a.name;

    switch (i) {
      case "back_btn":
        if (n.GlobalParams.PlayGuideMode) return void p["default"].showNewToast("引导中请勿操作");
        n.GlobalParams.JoinMatchGame = !1, n.GlobalParams.MathcTimeInfo.open = !0, n.GlobalParams.TryNewHero = !1, this.node.destroy();
        break;

      case "use_card_btn":
      case "sure_btn":
        var r = function r() {
          if (n.GlobalParams.ChangeGameMode != _.GameType.clone_mode) o.showHeroSkillInfo();else {
            o.myChooseHero(), o.sure_btn_node.getComponent(cc.Button).interactable = !1, o.sure_btn_node.active = !0, o.get_btn_node.parent.active = !1;
            var e = Math.floor(n.GlobalParams.MatchMyIndex / 2);
            (n.GlobalParams.MatchMyIndex % 2 == 0 ? o.left_pleyer_node.children[e] : o.right_player_node.children[e]).getComponent(f["default"]).showMyPlayerInfo();
          }
        };

        "use_card_btn" == i ? n.GlobalParams.PlayerInfo.value.tast_card > 0 ? (this.uiManager.addTykNum(-1), this.is_use_card = !0, r()) : this.uiManager.showPopup("GetZsViewUI", function (e) {
          e.getComponent(g["default"]).showPopupInfoView(3);
        }) : r();
        break;

      case "get_btn":
        this.buyRoleSke();
        break;

      case "reelect_btn":
        this.hero_view_ui.active = !0, this.choose_hero_skill_view.active = !1;
        break;

      case "dower_btn":
        this.choose_dower_node.active = !this.choose_dower_node.active;
        break;

      case "skill_1":
      case "skill_2":
      case "skill_3":
      case "skill_4":
      case "skill_5":
      case "skill_6":
        this.playerChooseSkill(i);
        break;

      case "dower_0":
      case "dower_1":
      case "dower_2":
      case "dower_3":
        n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].dower_info = a.getComponent(m["default"]).getDowerInfo(), this.showDowerInfo();
    }
  }, t.prototype.showHeroSkillInfo = function () {
    this.myChooseHero();
    var e = Math.floor(n.GlobalParams.MatchMyIndex / 2);
    (n.GlobalParams.MatchMyIndex % 2 == 0 ? this.left_pleyer_node.children[e] : this.right_player_node.children[e]).getComponent(f["default"]).showMyPlayerInfo(), this.showChooseSkillInfo(), this.showMyChooseHero(), this.hero_view_ui.active = !1, this.choose_hero_skill_view.active = !0;
  }, t.prototype.showCountDown = function () {
    var e = this;

    if (this.time_num_label.string = this.count_down + "秒", n.GlobalParams.ChangeGameMode == _.GameType.clone_mode || this.choose_hero_skill_view.active || 5 != this.count_down || this.showHeroSkillInfo(), n.GlobalParams.ChangeGameMode == _.GameType.clone_mode && 10 == this.count_down) {
      for (var t = [], o = [], a = 0; a < n.GlobalParams.MatchGamePlayer.length; a++) {
        a % 2 == 0 ? t.push(n.GlobalParams.MatchGamePlayer[a].role_id) : o.push(n.GlobalParams.MatchGamePlayer[a].role_id);
      }

      t = t.sort(function (e, t) {
        return e - t;
      }), o = o.sort(function (e, t) {
        return e - t;
      });
      var i = 0,
          r = 0,
          s = !1,
          l = !1;

      for (a = 0; a < 5; a++) {
        0 == a ? (i = t[a], r = o[a]) : (s || i != t[a] ? i = s ? i : t[a] : s = !0, l || r != o[a] ? r = l ? r : o[a] : l = !0);
      }

      for (a = 0; a < n.GlobalParams.MatchGamePlayer.length; a++) {
        n.GlobalParams.MatchGamePlayer[a].role_id = a % 2 == 0 ? i : r;
        var c = Math.floor(a / 2);
        (a % 2 == 0 ? this.left_pleyer_node.children[c] : this.right_player_node.children[c]).getComponent(f["default"]).updatePlayerInfo();
      }

      this.showChooseSkillInfo(), this.showMyChooseHero(), this.hero_view_ui.active = !1, this.choose_hero_skill_view.active = !0;
    }

    this.count_down <= 0 ? (this.uiManager.showPopup("LoadingViewUI"), this.node.destroy()) : this.scheduleOnce(function () {
      e.count_down--, e.showCountDown();
    }, 1);
  }, t.prototype.myChooseHero = function () {
    var e,
        t = n.GlobalParams.playerSkinInfo.value;
    e = this.choose_hero_index < 1 ? 1 == t.have_hero.length ? t.use[0] : t.have_hero[l["default"].getRandomInt(0, t.have_hero.length - 1)] : -1 != t.have_hero.indexOf(this.choose_hero_index) || this.is_use_card ? this.choose_hero_index : 1 == t.have_hero.length ? t.use[0] : t.have_hero[l["default"].getRandomInt(0, t.have_hero.length - 1)], n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].role_id = e;
  }, t.prototype.showPlayerViewInfo = function () {
    for (var e = 0; e < 10; e++) {
      var t = Math.floor(e / 2);
      (e % 2 == 0 ? this.left_pleyer_node.children[t] : this.right_player_node.children[t]).getComponent(f["default"]).showChoosePlayerInfo(e);
    }
  }, t.prototype.showGameHeroView = function () {
    this.GameHeroList = [];
    var e = c["default"].Role_info,
        t = n.GlobalParams.playerSkinInfo.value,
        o = [],
        a = [];
    n.GlobalParams.TryNewHero && this.GameHeroList.push(n.GlobalParams.NewHeroId), this.GameHeroList.push(-1), this.GameHeroList.push(n.GlobalParams.playerSkinInfo.value.use[0]);

    for (var i = 0; i < n.GlobalParams.GameHeroIndex.length; i++) {
      var r = n.GlobalParams.GameHeroIndex[i];
      -1 == t.have_hero.indexOf(r) ? a.push(r) : -1 == this.GameHeroList.indexOf(r) && o.push(r);
    }

    for (this.GameHeroList = this.GameHeroList.concat(o).concat(a), i = 0; i < this.GameHeroList.length; i++) {
      r = this.GameHeroList[i];
      var s = null;
      this.hero_view_count.children[i] ? s = this.hero_view_count.children[i] : (s = cc.instantiate(this.hero_node_item)).setParent(this.hero_view_count), s.active = !0, s.getComponent(v["default"]).showRoleInfo(-1 != r ? e[r] : "", r);
    }
  }, t.prototype.chooseRoleInfo = function (e, t) {
    this.choose_hero_index = t;
    var o = n.GlobalParams.playerSkinInfo.value;
    -1 == this.choose_hero_index ? this.get_btn_node.parent.active = !1 : this.get_btn_node.parent.active = -1 == o.have_hero.indexOf(this.choose_hero_index), this.get_way_node.active = this.get_btn_node.parent.active, this.sure_btn_node.active = !this.get_btn_node.parent.active, this.get_way_node.active && this.showRoleSkeBtn(this.choose_hero_index);
  }, t.prototype.showRoleSkeBtn = function (e) {
    for (var t = _["default"].shop_role_info[e], o = 0; o < this.get_way_node.childrenCount; o++) {
      this.get_way_node.children[o].active = t.type == o;
    }

    0 == t.type ? this.get_way_node.children[0].getChildByName("num").getComponent(cc.Label).string = "" + t.num * t.discount : 1 == t.type && (this.get_way_node.children[1].getChildByName("num").getComponent(cc.Label).string = "" + t.num * t.discount), this.get_btn_node.getComponent(cc.Button).interactable = -1 != [0, 1, 4].indexOf(t.type);
  }, t.prototype.buyRoleSke = function () {
    var e = this,
        t = _["default"].shop_role_info[this.choose_hero_index],
        o = function o() {
      var o = n.GlobalParams.playerSkinInfo.value;
      o.use[0] = t.id, o.have_hero.push(t.id), n.GlobalParams.playerSkinInfo.value = o, e.uiManager.showPopup("ObtainHeroTipView"), e.emitEvent(a["default"].SEND_UPDATE_CHOOSE_HERO_LIST);
    },
        i = n.GlobalParams.PlayerInfo.value;

    if (this.get_way_node.children[0].active) u["default"].getInstance().showVideo(function (e) {
      r["default"].playGameBGM(), e == u.ResultEnum.Success && o();
    });else if (this.get_way_node.children[1].active) {
      var s = t.num * t.discount;
      i.coin >= s ? (this.uiManager.addCoinNum(-1 * s), o()) : this.uiManager.showPopup("ShopViewUI", function (e) {
        e.getComponent(d["default"]).showChooseType("coin_btn");
      });
    } else if (this.get_way_node.children[2].active) {
      var l = t.num * t.discount;
      i.zs >= l ? (this.uiManager.addZsNum(-1 * l), o()) : this.uiManager.showPopup("GetZsViewUI", function (e) {
        e.getComponent(g["default"]).showPopupInfoView(0);
      });
    }
  }, t.prototype.showMyChooseHero = function () {
    var e = this,
        t = c["default"].Role_info[n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].role_id];
    this.uiManager.getRoleSkele(t.id, function (t) {
      e.my_choose_hero_skeleton.skeletonData = t, e.my_choose_hero_skeleton.setAnimation(0, "battle_idle", !0);
    }), this.hero_name_sprite.spriteFrame = i["default"].getInstance().getHeroHeadFrame("hero_name_" + t.id);
  }, t.prototype.showChooseSkillInfo = function () {
    for (var e = n.GlobalParams.PlayerInfo.value, t = 0; t < this.skill_base_node.childrenCount; t++) {
      this.skill_base_node.children[t].getComponent(cc.Sprite).spriteFrame = i["default"].getInstance().getPlayerSkillFrame("skill_" + (h["default"].platform == h.EPlatform.TikTok ? "dy_" : "") + (t + 1)), this.skill_base_node.children[t].children[0].active = -1 != this.choose_skill.indexOf(t + 1), this.skill_base_node.children[t].children[1].active = -1 == e.unlock_skill.indexOf(t + 1) && !u["default"].getInstance().getGameTestVersion();
    }
  }, t.prototype.playerChooseSkill = function (e) {
    var t = this,
        o = Number(l["default"].getNameType(e, "skill_")),
        a = function a() {
      if (t.choose_skill[1] != o) {
        var e = [t.choose_skill[1], o];
        t.choose_skill = e, n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].player_skill = t.choose_skill;
      }

      t.showChooseSkillInfo();
    },
        i = n.GlobalParams.PlayerInfo.value;

    -1 != i.unlock_skill.indexOf(o) || u["default"].getInstance().getGameTestVersion() ? a() : u["default"].getInstance().showVideo(function (e) {
      r["default"].playGameBGM(), e == u.ResultEnum.Success && (i.unlock_skill.push(o), n.GlobalParams.PlayerInfo.value = i, a());
    });
  }, t.prototype.showDowerInfo = function () {
    var e = n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].dower_info[0];
    this.dower_btn_node.getComponent(m["default"]).showDowerInfo(e);

    for (var t = [], o = 0; o < 5; o++) {
      o != e && t.push(o);
    }

    for (o = 0; o < t.length; o++) {
      this.choose_dower_node.children[o].getComponent(m["default"]).showDowerInfo(t[o]);
    }
  }, oo([w(cc.Sprite)], t.prototype, "mode_type_sprite", void 0), oo([w(cc.Sprite)], t.prototype, "mode_hero_sprite", void 0), oo([w(cc.Node)], t.prototype, "left_pleyer_node", void 0), oo([w(cc.Node)], t.prototype, "right_player_node", void 0), oo([w(cc.Label)], t.prototype, "time_num_label", void 0), oo([w(cc.Node)], t.prototype, "hero_view_ui", void 0), oo([w(cc.Node)], t.prototype, "hero_node_item", void 0), oo([w(cc.Node)], t.prototype, "hero_view_count", void 0), oo([w(cc.Node)], t.prototype, "get_way_node", void 0), oo([w(cc.Node)], t.prototype, "get_btn_node", void 0), oo([w(cc.Node)], t.prototype, "sure_btn_node", void 0), oo([w(cc.Node)], t.prototype, "choose_hero_skill_view", void 0), oo([w(sp.Skeleton)], t.prototype, "my_choose_hero_skeleton", void 0), oo([w(cc.Sprite)], t.prototype, "hero_name_sprite", void 0), oo([w(cc.Node)], t.prototype, "skill_base_node", void 0), oo([w(cc.Node)], t.prototype, "choose_dower_node", void 0), oo([w(cc.Node)], t.prototype, "dower_btn_node", void 0), oo([w(cc.Node)], t.prototype, "reelect_btn", void 0), oo([I], t);
}(s["default"]);

o["default"] = b;

cc._RF.pop();